fetch_val('sendmail') eq 'manual'
    and return;

if (my $sendmail = fetchall_hash('sendmail'))
{
    while (my ($key, $val) = each %{ $sendmail })
    {
	file_append('/etc/mail/sendmail.mc', "define(`$key', `$val')dnl\n", qr/^(?:dnl )?define\(`$key'/, -reload => 'sendmail');
    }
}

my $listen = fetch_val('smtp');

my $smtp = $listen =~ /(^1$|\bsmtp\b)/ ? '' : 'Addr=127.0.0.1,';
my $submission = $listen =~ /\bsubmission\b/ ? '' : 'dnl ';
my $smtps = $listen =~ /\bsmtps\b/ ? '' : 'dnl ';

file_append('/etc/mail/sendmail.mc', "DAEMON_OPTIONS(`Port=smtp,${smtp} Name=MTA')dnl\n", qr/^(dnl )?DAEMON_OPTIONS\(`Port=smtp\b/, -reload => 'sendmail');
file_append('/etc/mail/sendmail.mc', "${smtps}DAEMON_OPTIONS(`Port=smtps, Name=TLSMTA, M=s')dnl\n", qr/^(dnl )?DAEMON_OPTIONS\(`Port=smtps\b/, -reload => 'sendmail');
file_append('/etc/mail/sendmail.mc', "${submission}DAEMON_OPTIONS(`Port=submission, Name=MSA, M=Ea')dnl\n", qr/^(dnl )?DAEMON_OPTIONS\(`Port=submission\b/, -reload => 'sendmail');

package_install 'sendmail-cf';

1;
